<%@page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@include file="/includes/taglibs.jsp"%>
<%@page import="com.feib.soeasy.util.UserUtil"%>
<%@page import="com.feib.soeasy.util.CodeTableUtil"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title><%=UserUtil.getCurrentMenuItemName() %></title>
	<script type="text/javascript" src="<c:url value='/scripts/jquery/jquery.bgiframe-2.1.2.js'/>"></script>
	<script type="text/javascript">
	<!--
	$(document).ready(function() {

		$('#findGroupNoImg').click(function() {
			var groupNo = $('#group\\.groupNo').val();
			
			if (null != groupNo && 0 != groupNo.length){
				var tmpGroupNo = parseInt(groupNo,10);
				if(! isNaN(tmpGroupNo)){
					$('#hidden\\.qryGroup\\.groupNo').val(groupNo);
					$('#hidden\\.qryGroup\\.groupName').val('');
					$('#qryGroup\\.groupNo').val(groupNo);
					$('#qryGroup\\.groupName').val('');
				}
				else{
					$('#hidden\\.qryGroup\\.groupNo').val('');
					$('#hidden\\.qryGroup\\.groupName').val(groupNo);
					$('#qryGroup\\.groupNo').val('');
					$('#qryGroup\\.groupName').val(groupNo);
					$("#queryGroupResultDiv").html('');
				}
				
				$("#findGroupDiv" ).dialog({  
					title:'帳單業者查詢' 
					, width: 600
					, resizable: true
					, modal: true
				});
				
				$('#doAjaxQueryGroupsBtn').click();
			}
			else{
				$('#hidden\\.qryGroup\\.groupNo').val('');
				$('#hidden\\.qryGroup\\.groupName').val('');
				$('#qryGroup\\.groupNo').val('');
				$('#qryGroup\\.groupName').val('');
				$("#queryGroupResultDiv").html('');
				$("#findGroupDiv" ).dialog({  
					title:'帳單業者查詢' 
					, width: 600
					, resizable: true
					, modal: true
				});
			}
		});


		$('#doAjaxQueryGroupsBtn').click(function() {
			var groupNo = $('#qryGroup\\.groupNo').val();
			var groupName = $('#qryGroup\\.groupName').val();
			$("#queryGroupResultDiv").html('');

			$('#hidden\\.qryGroup\\.groupNo').val(groupNo);
			$('#hidden\\.qryGroup\\.groupName').val(groupName);
			doQueryGroupAction(1);
			
		});


		$('#doAjaxCloseGroupsBtn').click(function() {
			$("#findGroupDiv" ).dialog( "close" );
		});
		
		$('#doQueryBtn').click(function() {
			var errMsg = "";
			var groupNo = $('#group\\.groupNo').val();
			
			if (null == groupNo || 0 == groupNo.length){
				errMsg = errMsg + "業者代號是必要欄位<br/>";
			}//2011/06/16 jeff Gu  start   修正    業者代號不存在時 查詢錯誤問題
			else if (12 != groupNo.length){
				errMsg = errMsg + "業者代號 為固定長度12碼<br/>";
			}
			//2011/06/16 jeff Gu  end   修正    業者代號不存在時 查詢錯誤問題

			
			if (0 != errMsg.length){
				$("#ajaxErrorMessageDiv").html(errMsg);
				$("#ajaxErrorMessageDiv" ).dialog({  
					title:'請修正下列錯誤' 
					,width: 300
					, resizable: false
					, modal: true
					, buttons: {
						Ok: function() {
							$( this ).dialog( "close" );
						}
					}
				});
				return false;
			}
			
			$('#hidden\\.group\\.groupNo').val(groupNo);
			
			doQueryAction(1);
		});
		

		
		$( "#doBtn5" ).click(function() {
			var errMsg = "";
			var reason = $('#reason').val();
			
			if (null == reason || 0 == reason.length){
				errMsg = errMsg + "請輸入原因<br/>";
			}
			if (0 != errMsg.length){
				$("#ajaxErrorMessageDiv").html(errMsg);
				$("#ajaxErrorMessageDiv" ).dialog({  
					title:'請修正下列錯誤' 
					,width: 300
					, resizable: false
					, modal: true
					, buttons: {
						Ok: function() {
							$( this ).dialog( "close" );
						}
					}
				});
				return false;
			}
			$("#hidden6\\.reason").val(reason);
			waitingDialog({});
			$.ajax({url : "<c:url value='/ajax/Soez5001.action'/>",
				async : false,
				type : 'POST',
				data : $("#feedbackLogReasonHiddenFrom").serialize(),
				dataType : 'html',
				success : function(data, textStatus, XMLHttpRequest){
					$("#ajaxErrorMessageDiv").html(data);
					$("#ajaxErrorMessageDiv").dialog({
						title : '<%=UserUtil.getCurrentMenuItemName() %>',
						width : 300,
						resizable : false,
						modal : true,
						buttons : {
							Ok : function() {
								
								if ((1==$("#doWriteOffPaymentResultCode").val()) || (1==$("#doSkipFeedbackLogResultCode").val())){
									$("#feedbackLogReasonDiv").dialog("close");
									$("#feedbackLogDiv").dialog("close");
									doQueryAction();
								}
								
								$(this).dialog("close");
							}
						}
					});
					},
				error : function(XMLHttpRequest, textStatus, errorThrown){
					$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
					$("#ajaxErrorMessageDiv" ).dialog({  
						title:'系統錯誤' 
						,width: 600
						, resizable: false
						, modal: true
						, buttons: {
							Ok: function() {
								$( this ).dialog( "close" );
							}
						}
					});
					},
				complete: function(XMLHttpRequest, textStatus){
					closeWaitingDialog();
				}
			});
		});
		
		$("#exitBtn5").click(function() {
			$("#feedbackLogReasonDiv").dialog( "close" );
		});
				
	});
	

	function doQueryGroupAction(pageNumber)
	{
		$('#hidden\\.queryGroupResult\\.pageNumber').val(pageNumber);
		$("#queryGroupResultDiv").fadeTo("slow", 0.1);//動態漸變調整元素透明度，且可在開關完畢後執行一函式。(寬高不變)

		waitingDialog({});
		$.ajax({url : "<c:url value='/ajax/Soez5001.action'/>",
			async : true,//是否同部請求
			type : 'POST',
			data : $("#queryGroupHiddenFrom").serialize(),//傳送至Server的資料，會自動轉為query string的型式，如果是GET請求還會幫你附加到URL。
			//序列化表單 input 內容為「name1=value1&name2=value3···」格式的字串。
			dataType : 'html',//預期Server傳回的資料類型，如果沒指定，jQuery會根據HTTP MIME Type自動選擇以responseXML或responseText傳入你的success callback。
			success : function(data, textStatus, XMLHttpRequest){
					$("#queryGroupResultDiv").html(data);/* 設定匹配元素的HTML內容 － 有參數 */
				},
			error : function(XMLHttpRequest, textStatus, errorThrown){
				$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
				$("#ajaxErrorMessageDiv" ).dialog({  
					title:'系統錯誤' 
					,width: 600
					, resizable: false
					, modal: true
					, buttons: {
						Ok: function() {
							$( this ).dialog( "close" );
						}
					}
				});
				},
			complete: function(XMLHttpRequest, textStatus){
				if ($.browser.msie && /msie 6\.0/i.test(navigator.userAgent)){
					$("#findGroupDiv" ).dialog( "close" );
					$("#findGroupDiv" ).dialog( "open" );					
				}
				closeWaitingDialog();
				$("#queryGroupResultDiv").fadeTo("slow", 1);
			}
		});
	}

	
	function doQueryAction(pageNumber)
	{
		if (null != pageNumber)
			$('#hidden\\.queryResult\\.pageNumber').val(pageNumber);
		$('#method1').attr('name','doAjaxQuery');
		$("#queryResultDiv").fadeTo("slow", 0.1);

		waitingDialog({}); 
		$.ajax({url : "<c:url value='/ajax/Soez5001.action'/>",
			async : true,
			type : 'POST',
			data : $("#queryHiddenFrom").serialize(),
			dataType : 'html',
			success : function(data, textStatus, XMLHttpRequest){
					$("#queryResultDiv").html(data);
				},
			error : function(XMLHttpRequest, textStatus, errorThrown){
				$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
				$("#ajaxErrorMessageDiv" ).dialog({  
					title:'系統錯誤' 
					,width: 600
					, resizable: false
					, modal: true
					, buttons: {
						Ok: function() {
							$( this ).dialog( "close" );
						}
					}
				});
				},
			complete: function(XMLHttpRequest, textStatus){
				closeWaitingDialog();
				$("#queryResultDiv").fadeTo("slow", 1);
			}
		});
		
	}
	
	

	function doQueryFeedbackLogAction(uid)//修改送出查詢單筆資料
	{   
		$('#hidden\\.feedbackUid').val(uid);
		waitingDialog({});
		$.ajax({url : "<c:url value='/ajax/Soez5001.action'/>",
			async : true,
			type : 'POST',
			data : $("#queryFeedbackLogHiddenForm").serialize(),
			dataType : 'html',
			success : function(data, textStatus, XMLHttpRequest){
				$("#feedbackLogDiv").html(data);
				$( "#feedbackLogDiv" ).dialog({  title:'<%=UserUtil.getCurrentMenuItemName() %>' ,width: 600, resizable: false, modal: true  });
				},
			error : function(XMLHttpRequest, textStatus, errorThrown){
					$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
					$("#ajaxErrorMessageDiv" ).dialog({  
						title:'系統錯誤' 
						,width: 600
						, resizable: false
						, modal: true
						, buttons: {
							Ok: function() {
								$( this ).dialog( "close" );
							}
						}
					});
				},
			complete: function(XMLHttpRequest, textStatus){closeWaitingDialog();}
		});
	}
	

	function doDownloadExcelFileAction()
	{
		$('#method1').attr('name','doAjaxDownloadExcelFile');
		
		$.download("<c:url value='/ajax/Soez5001.action'/>",$("#queryHiddenFrom").serialize() );		
	}
	
	jQuery.download = function(url, data, method){
		if( url && data ){
			//data can be string of parameters or array/object
			data = typeof data == 'string' ? data : jQuery.param(data);
			//split params into form inputs
			//send request
			if (null == $('#myIFrm')){
				jQuery('<iframe id="myIFrm" src="' + url + '?'+ data +'" style="display:none; visibility: hidden;"></iframe>').appendTo('body');
			}
			else {
				$('#myIFrm').attr("src", url + '?'+ data );
			}
			
			
		};
	};
		
		
		
		
	
	
	//-->
	</script>
</head>
<body>
<div id="mainAreaCT">
		<jsp:include page="/includes/path.jsp"/>
		<jsp:include page="/includes/subMenu.jsp"/>
		
	<div id="queryFormDiv">
		<stripes:form id="queryPaymentFrom" beanclass="com.feib.soeasy.action.Soez5001ActionBean" 
			method="post" onsubmit="javascript: return false;">
		<table id="queryForm">
			<tr>			
				<th>業者代號<span id="mustKeyInStar">**</span></th>				
				<td>
				<%if ( UserUtil.isBankGroup()){ %>				
					<div id="findGroupNoImg"><a href="javascript: void(0)" class="btnZoom">查詢</a></div>
					<stripes:text id="group.groupNo" name="group.groupNo" size="12" maxlength="12" />
     				<span id="hidden.qryGroup.groupName.span"><c:out value="${actionBean.qryGroup.groupName }"/></span>
				 <%} else {%>
				  <input type="text" readonly="readonly" id="group.groupNo" name="group.groupNo" value="<%out.print(UserUtil.getUserGroup().getGroupNo());%>" size="12"/>				  
				  <span id="qryFormatDefinition.group.groupName.span"><%=UserUtil.getUserGroup().getGroupName()%></span>
				 <%}%>			
				</td>
			</tr>
           <tr>
				<td colspan="2" class="queryFunction">
					<stripes:button id="doQueryBtn" name="doQueryBtn" value="查詢"/>
				</td>
			</tr>
		</table>
		</stripes:form>
	</div><!-- end #queryForm -->
	
	<!-- 查詢結果  -->
	<div id="queryResultDiv" style="display: none;"></div>
	
	<div id="queryHiddenFormDiv" style="display: none;">
		<stripes:form id="queryHiddenFrom" beanclass="com.feib.soeasy.action.Soez5001ActionBean" 
			method="post" onsubmit="javascript: return false;">
			<stripes:hidden id="hidden.group.groupNo" name="group.groupNo"/>
			<stripes:hidden id="hidden.queryResult.pageNumber" name="queryResult.pageNumber" />
			
			<input type="hidden" id="method1" name="doAjaxQuery"/>
		</stripes:form>
	</div>
	
	<!-- 異常處理明細查詢 -->
	<div id="feedbackLogDiv" style="display: none;"></div>
	<div id="queryFeedbackLogHiddenFormDiv" style="display: none; ">
		<stripes:form id="queryFeedbackLogHiddenForm" beanclass="com.feib.soeasy.action.Soez5001ActionBean" 
			method="post" onsubmit="javascript: return false;">			
			<stripes:text id="hidden.feedbackUid" name="feedbackUid"/>
			<input type="hidden" id="method2" name="doAjaxQueryFeedbackLog"/>
		</stripes:form>
	</div>
	
	

	<div id="feedbackLogReasonDiv" style="display: none;">
		<table id="paymentListTable">
			<tr>
				<th><span id="spanReason">處理原因</span></th>
				<td>
					<input type="text" id="reason" name="reason" size="30" maxlength="100" />
				</td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					<input type="button" id="doBtn5" name="doBtn5" value="確認"/>
		    		<input type="button" id="exitBtn5" name="exitBtn5" value="離開"/>
				</td>
			</tr>
		</table>
	</div>
	<div id="feedbackLogReasonHiddenFromDiv" style="display: none; ">
		<stripes:form id="feedbackLogReasonHiddenFrom" beanclass="com.feib.soeasy.action.Soez5001ActionBean" 
			method="post" onsubmit="javascript: return false;">			
			<input type="hidden" id="hidden6.paymentPk" name="paymentPk"/>
			<input type="hidden" id="hidden6.reason" name="reason"/>
		    <input type="hidden" id="hidden6.feedbackUid" name="feedbackUid" />						
			<input type="hidden" id="method6" name="doWriteOffPayment"/>
		</stripes:form>
	</div>
	
	
	<!-- 業者代號 查詢 -->
	<div id="findGroupDiv" style="display: none;">
		<div id="queryGroupDiv">
		<table>
			<tr>
				<th>業者代號</th>
				<td><input id="qryGroup.groupNo" type="text" size="12" maxlength="12" /> </td>
			</tr>
			<tr>
				<th>名稱</th>
				<td><input id="qryGroup.groupName" type="text" size="20" /></td>
			</tr>
			<tr>
				<td colspan="2" class="queryFunction">
					<input type="button" value="查詢" id="doAjaxQueryGroupsBtn"/>
					<input type="button" value="離開" id="doAjaxCloseGroupsBtn"/>
				</td>
			</tr>
		</table>
		</div>
		<div id="queryGroupResultDiv" style="display: none;">
		</div>
	</div>
	<div id="queryGroupHiddenFormDiv" style="display: none; ">
		<stripes:form id="queryGroupHiddenFrom" beanclass="com.feib.soeasy.action.Soez5001ActionBean" 
			method="post" onsubmit="javascript: return false;">
			<stripes:hidden id="hidden.qryGroup.groupName" name="qryGroup.groupName"/>
			<stripes:hidden id="hidden.qryGroup.groupNo" name="qryGroup.groupNo"/>	
			<stripes:hidden id="hidden.queryGroupResult.pageNumber" name="queryGroupResult.pageNumber" />			
			<input type="hidden" id="method" name="doAjaxQueryGroups"/>
		</stripes:form>
	</div>
<!-- 帳單明細查詢 -->

	
	<!-- Message -->
	<div id="ajaxErrorMessageDiv" style="display: none;"></div>
	
	<iframe id="myIFrm" src="" style="display:none; visibility: hidden;"></iframe>


</div>
</body>
</html>